from tkinter import *

root = Tk()
def callback(event):
    print("按键位置:",event.char)
    if(event.char == 'x'):
        print("按对啦!")
        var.set("按对啦!")
    else:
        print("按错啦,要按x键!")
        var.set("按错啦,要按x键")
        
var = Variable()
var.set("请按下x键")
frame = Frame(root,width = 200,height = 200)
Label(root,textvariable = var,bg = "green").pack()
frame.bind("<Key>",callback)
frame.focus_set()   
frame.pack()

mainloop()
